static void atk_action_interface_init (AtkActionIface *iface);
-G_DEFINE_TYPE_WITH_CODE (GtkExpanderAccessible, gtk_expander_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
+G_DEFINE_TYPE_WITH_CODE (GtkExpanderAccessible, gtk_expander_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
static const gchar *
gtk_expander_accessible_get_n_children (AtkObject *obj)
{
GtkWidget *widget;
- GList *children;
- gint count = 0;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return 0;
- children = gtk_container_get_children (GTK_CONTAINER(widget));
- count = g_list_length (children);
- g_list_free (children);
+ if (gtk_expander_get_child (GTK_EXPANDER (widget)))
+ return 1;
- /* See if there is a label - if there is, reduce our count by 1
- * since we don't want the label included with the children.
- */
- if (gtk_expander_get_label_widget (GTK_EXPANDER (widget)))
- count -= 1;
-
- return count;
+ return 0;
}
static AtkObject *
gtk_expander_accessible_ref_child (AtkObject *obj,
gint i)
{
- GList *children, *tmp_list;
AtkObject *accessible;
GtkWidget *widget;
- GtkWidget *label;
- gint index;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return NULL;
- children = gtk_container_get_children (GTK_CONTAINER (widget));
-
- /* See if there is a label - if there is, we need to skip it
- * since we don't want the label included with the children.
- */
- label = gtk_expander_get_label_widget (GTK_EXPANDER (widget));
- if (label)
- {
- for (index = 0; index <= i; index++)
- {
- tmp_list = g_list_nth (children, index);
- if (label == GTK_WIDGET (tmp_list->data))
- {
- i += 1;
- break;
- }
- }
- }
-
- tmp_list = g_list_nth (children, i);
- if (!tmp_list)
- {
- g_list_free (children);
- return NULL;
- }
- accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
+ widget = gtk_expander_get_child (GTK_EXPANDER (widget));
+ if (widget == NULL)
+ return NULL;
- g_list_free (children);
+ accessible = gtk_widget_get_accessible (widget);
g_object_ref (accessible);
return accessible;
}
struct _GtkExpander
{
- GtkContainer parent_instance;
+ GtkWidget parent_instance;
GtkWidget *label_widget;
struct _GtkExpanderClass
{
- GtkContainerClass parent_class;
+ GtkWidgetClass parent_class;
void (* activate) (GtkExpander *expander);
};
static gboolean gtk_expander_focus (GtkWidget *widget,
GtkDirectionType direction);
-static void gtk_expander_add (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_expander_remove (GtkContainer *container,
- GtkWidget *widget);
-
static void gtk_expander_activate (GtkExpander *expander);
gdouble y,
GtkExpander *expander);
-G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_CONTAINER,
+G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_expander_buildable_init))
}
}
-static void
-gtk_expander_forall (GtkContainer *container,
- GtkCallback callback,
- gpointer user_data)
+static GtkSizeRequestMode
+gtk_expander_get_request_mode (GtkWidget *widget)
{
- GtkExpander *expander = GTK_EXPANDER (container);
+ GtkExpander *expander = GTK_EXPANDER (widget);
if (expander->child)
- (*callback) (expander->child, user_data);
+ return gtk_widget_get_request_mode (expander->child);
+ else
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+}
- if (expander->label_widget)
- (*callback) (expander->label_widget, user_data);
+static void
+gtk_expander_compute_expand (GtkWidget *widget,
+ gboolean *hexpand,
+ gboolean *vexpand)
+{
+ GtkExpander *expander = GTK_EXPANDER (widget);
+
+ if (expander->child)
+ {
+ *hexpand = gtk_widget_compute_expand (expander->child, GTK_ORIENTATION_HORIZONTAL);
+ *vexpand = gtk_widget_compute_expand (expander->child, GTK_ORIENTATION_VERTICAL);
+ }
+ else
+ {
+ *hexpand = FALSE;
+ *vexpand = FALSE;
+ }
}
static void
gtk_expander_class_init (GtkExpanderClass *klass)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
-
- gobject_class = (GObjectClass *) klass;
- widget_class = (GtkWidgetClass *) klass;
- container_class = (GtkContainerClass *) klass;
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gobject_class->dispose = gtk_expander_dispose;
gobject_class->set_property = gtk_expander_set_property;
widget_class->focus = gtk_expander_focus;
widget_class->grab_focus = gtk_widget_grab_focus_self;
widget_class->measure = gtk_expander_measure;
-
- container_class->add = gtk_expander_add;
- container_class->remove = gtk_expander_remove;
- container_class->forall = gtk_expander_forall;
+ widget_class->compute_expand = gtk_expander_compute_expand;
+ widget_class->get_request_mode = gtk_expander_get_request_mode;
klass->activate = gtk_expander_activate;
{
if (g_strcmp0 (type, "label") == 0)
gtk_expander_set_label_widget (GTK_EXPANDER (buildable), GTK_WIDGET (child));
+ else if (GTK_IS_WIDGET (child))
+ gtk_expander_set_child (GTK_EXPANDER (buildable), GTK_WIDGET (child));
else
parent_buildable_iface->add_child (buildable, builder, child, type);
}
return TRUE;
}
-static void
-gtk_expander_add (GtkContainer *container,
- GtkWidget *widget)
-{
- GtkExpander *expander = GTK_EXPANDER (container);
-
- if (expander->child != NULL)
- {
- g_warning ("Attempting to add a widget with type %s to a %s, "
- "but a %s can only contain one widget at a time; "
- "it already contains a widget of type %s",
- g_type_name (G_OBJECT_TYPE (widget)),
- g_type_name (G_OBJECT_TYPE (container)),
- g_type_name (G_OBJECT_TYPE (container)),
- g_type_name (G_OBJECT_TYPE (expander->child)));
- return;
- }
-
- if (expander->expanded)
- {
- gtk_container_add (GTK_CONTAINER (expander->box), widget);
- }
- else
- {
- if (g_object_is_floating (widget))
- g_object_ref_sink (widget);
-
- g_object_ref (widget);
- }
-
- expander->child = widget;
-}
-
-static void
-gtk_expander_remove (GtkContainer *container,
- GtkWidget *widget)
-{
- GtkExpander *expander = GTK_EXPANDER (container);
-
- if (expander->label_widget == widget)
- gtk_expander_set_label_widget (expander, NULL);
- else
- {
- gtk_container_remove (GTK_CONTAINER (expander->box), widget);
- if (!expander->expanded)
- {
- /* We hold an extra ref */
- g_object_unref (widget);
- }
- GTK_CONTAINER_CLASS (gtk_expander_parent_class)->remove (container, widget);
- }
-}
-
static void
gtk_expander_activate (GtkExpander *expander)
{
g_return_if_fail (GTK_IS_EXPANDER (expander));
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
- g_clear_pointer (&expander->child, gtk_widget_unparent);
+ if (expander->child)
+ {
+ gtk_container_remove (GTK_CONTAINER (expander->box), expander->child);
+ if (!expander->expanded)
+ g_object_unref (expander->child);
+ }
expander->child = child;
if (expander->child)
- gtk_widget_set_parent (expander->child, GTK_WIDGET (expander));
+ {
+ if (expander->expanded)
+ gtk_container_add (GTK_CONTAINER (expander->box), expander->child);
+ else
+ {
+ if (g_object_is_floating (expander->child))
+ g_object_ref_sink (expander->child);
+ g_object_ref (expander->child);
+ }
+ }
g_object_notify (G_OBJECT (expander), "child");
}